package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlGlossaryEntries entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlGlossaryEntries
 * @author MyEclipse Persistence Tools
 */

public class MdlGlossaryEntriesDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlGlossaryEntriesDAO.class);
	// property constants
	public static final String GLOSSARYID = "glossaryid";
	public static final String USERID = "userid";
	public static final String CONCEPT = "concept";
	public static final String DEFINITION = "definition";
	public static final String DEFINITIONFORMAT = "definitionformat";
	public static final String DEFINITIONTRUST = "definitiontrust";
	public static final String ATTACHMENT = "attachment";
	public static final String TIMECREATED = "timecreated";
	public static final String TIMEMODIFIED = "timemodified";
	public static final String TEACHERENTRY = "teacherentry";
	public static final String SOURCEGLOSSARYID = "sourceglossaryid";
	public static final String USEDYNALINK = "usedynalink";
	public static final String CASESENSITIVE = "casesensitive";
	public static final String FULLMATCH = "fullmatch";
	public static final String APPROVED = "approved";

	public void save(MdlGlossaryEntries transientInstance) {
		log.debug("saving MdlGlossaryEntries instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlGlossaryEntries persistentInstance) {
		log.debug("deleting MdlGlossaryEntries instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlGlossaryEntries findById(java.lang.Long id) {
		log.debug("getting MdlGlossaryEntries instance with id: " + id);
		try {
			MdlGlossaryEntries instance = (MdlGlossaryEntries) getSession()
					.get("idv.loveloser.dao.MdlGlossaryEntries", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlGlossaryEntries instance) {
		log.debug("finding MdlGlossaryEntries instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlGlossaryEntries")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlGlossaryEntries instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from MdlGlossaryEntries as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByGlossaryid(Object glossaryid) {
		return findByProperty(GLOSSARYID, glossaryid);
	}

	public List findByUserid(Object userid) {
		return findByProperty(USERID, userid);
	}

	public List findByConcept(Object concept) {
		return findByProperty(CONCEPT, concept);
	}

	public List findByDefinition(Object definition) {
		return findByProperty(DEFINITION, definition);
	}

	public List findByDefinitionformat(Object definitionformat) {
		return findByProperty(DEFINITIONFORMAT, definitionformat);
	}

	public List findByDefinitiontrust(Object definitiontrust) {
		return findByProperty(DEFINITIONTRUST, definitiontrust);
	}

	public List findByAttachment(Object attachment) {
		return findByProperty(ATTACHMENT, attachment);
	}

	public List findByTimecreated(Object timecreated) {
		return findByProperty(TIMECREATED, timecreated);
	}

	public List findByTimemodified(Object timemodified) {
		return findByProperty(TIMEMODIFIED, timemodified);
	}

	public List findByTeacherentry(Object teacherentry) {
		return findByProperty(TEACHERENTRY, teacherentry);
	}

	public List findBySourceglossaryid(Object sourceglossaryid) {
		return findByProperty(SOURCEGLOSSARYID, sourceglossaryid);
	}

	public List findByUsedynalink(Object usedynalink) {
		return findByProperty(USEDYNALINK, usedynalink);
	}

	public List findByCasesensitive(Object casesensitive) {
		return findByProperty(CASESENSITIVE, casesensitive);
	}

	public List findByFullmatch(Object fullmatch) {
		return findByProperty(FULLMATCH, fullmatch);
	}

	public List findByApproved(Object approved) {
		return findByProperty(APPROVED, approved);
	}

	public List findAll() {
		log.debug("finding all MdlGlossaryEntries instances");
		try {
			String queryString = "from MdlGlossaryEntries";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlGlossaryEntries merge(MdlGlossaryEntries detachedInstance) {
		log.debug("merging MdlGlossaryEntries instance");
		try {
			MdlGlossaryEntries result = (MdlGlossaryEntries) getSession()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlGlossaryEntries instance) {
		log.debug("attaching dirty MdlGlossaryEntries instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlGlossaryEntries instance) {
		log.debug("attaching clean MdlGlossaryEntries instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}